<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function f(val,valu) {
           var arr =  document.getElementById(val).value;
           var num = document.getElementById(valu).value;
           arr = arr.split(",");
           for (var i = 0; i < arr.length; i++){
               if (arr[i]==num){
                   alert(num+"在数组["+arr+"]的索引位置是"+i);
                   break;
               }else if (i==arr.length-1){
                   alert("数组["+arr+"]中没有"+num+"元素");
               }
           }
        }
    </script>
</head>
<body>
    字符串数组格式:(a,哈哈,3):<input id="a" type="text">
    要查找的元素:<input id="b"type="text">
    <button onclick="f('a','b')">开始查找</button>
</body>
</html>